home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / asy.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  7KB  |  294 lines

  1. /*
  2.     Generic serial line interface routines
  3.      Copyright 1991 Phil Karn, KA9Q
  4. */
  5.  
  6. /****************************************************************************
  7. *    $Id: asy.c 1.4 94/01/26 13:54:29 ROOT_DOS Exp $
  8. *    14 Jul 93    1.2        GT    Fix warnings.    
  9. *    24 Jan 94    1.4        GT    User specified flags.    
  10. *
  11. *  Atari version by David Nash - dnash@chaos.demon.co.uk
  12. *
  13. *        Include st_asy.h in place of 8250.h
  14. *
  15. ****************************************************************************/
  16.  
  17. #include <stdio.h>
  18. #include "global.h"
  19. #include "config.h"
  20. #include "proc.h"
  21. #include "iface.h"
  22. #include "netuser.h"
  23. #include "slhc.h"
  24. #ifdef ATARI
  25. #include "st_asy.h"
  26. #else
  27. #include "8250.h"
  28. #endif
  29. #include "asy.h"
  30. #include "ax25.h"
  31. #include "kiss.h"
  32. #include "nrs.h"
  33. #include "pktdrvr.h"
  34. #include "slip.h"
  35. #include "ppp.h"
  36. #include "commands.h"
  37.  
  38. static int asy_detach __ARGS((struct iface *ifp));
  39.  
  40.  
  41. /* Attach a serial interface to the system
  42.  * argv[0]: hardware type, must be "asy"
  43.  * argv[1]: I/O address, e.g., "0x3f8"
  44.  * argv[2]: vector, e.g., "4"
  45.  * argv[3]: mode, may be:
  46.  *        "slip" (point-to-point SLIP)
  47.  *        "ax25" (AX.25 frame format in SLIP for raw TNC)
  48.  *        "nrs" (NET/ROM format serial protocol)
  49.  *        "ppp" (Point-to-Point Protocol, RFC1171, RFC1172)
  50.  * argv[4]: interface label, e.g., "sl0"
  51.  * argv[5]: receiver ring buffer size in bytes
  52.  * argv[6]: maximum transmission unit, bytes
  53.  * argv[7]: interface speed, e.g, "9600"
  54.  * argv[8]: optional flags,
  55.  *        'v' for Van Jacobson TCP header compression (SLIP only,
  56.  *            use ppp command for VJ compression with PPP);
  57.  */
  58. int
  59. asy_attach(argc,argv,p)
  60. int argc;
  61. char *argv[];
  62. void *p;
  63. {
  64.     register struct iface *ifp;
  65.     struct asy *asyp;
  66.     int dev;
  67.     int trigchar = -1;
  68.     char monitor = FALSE;
  69. #if    defined(SLIP) || defined(AX25)
  70.     struct slip *sp;
  71.     char *ifn;
  72.     int xdev;
  73. #endif
  74. #ifdef    NRS
  75.     struct nrs *np;
  76. #endif
  77.  
  78.     if(if_lookup(argv[4]) != NULLIF){
  79.         tprintf("Interface %s already exists\n",argv[4]);
  80.         return -1;
  81.     }
  82.     /* Find unused asy control block */
  83.     for(dev=0;dev < ASY_MAX;dev++){
  84.         asyp = &Asy[dev];
  85.         if(asyp->iface == NULLIF)
  86.             break;
  87.     }
  88.     if(dev >= ASY_MAX){
  89.         tprintf("Too many asynch controllers\n");
  90.         return -1;
  91.     }
  92.  
  93.     /* Create interface structure and fill in details */
  94.     ifp = (struct iface *)callocw(1,sizeof(struct iface));
  95.     ifp->addr = Ip_addr;
  96.     ifp->name = strdup(argv[4]);
  97.     ifp->mtu = atoi(argv[6]);
  98.     ifp->dev = dev;
  99.     ifp->stop = asy_detach;
  100.     ifp->dial_me = FALSE;
  101.  
  102. #ifdef    SLIP
  103.     if(stricmp(argv[3],"SLIP") == 0) {
  104.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  105.             sp = &Slip[xdev];
  106.             if(sp->iface == NULLIF)
  107.                 break;
  108.         }
  109.         if(xdev >= SLIP_MAX) {
  110.             tprintf("Too many slip devices\n");
  111.             return -1;
  112.         }
  113.         setencap(ifp,"SLIP");
  114.         ifp->ioctl = asy_ioctl;
  115.         ifp->raw = slip_raw;
  116.         ifp->show = slip_status;
  117.         ifp->flags = 0;
  118.         ifp->xdev = xdev;
  119.  
  120.         sp->iface = ifp;
  121.         sp->send = asy_send;
  122.         sp->get = get_asy;
  123.         sp->type = CL_SERIAL_LINE;
  124.         trigchar = FR_END;
  125. #ifdef VJCOMPRESS
  126.         if((argc > 8) && (strchr(argv[8],'v') != NULLCHAR)) {
  127.             sp->escaped |= SLIP_VJCOMPR;
  128.             sp->slcomp = slhc_init(16,16);
  129.         }
  130. #else
  131.         sp->slcomp = NULL;
  132. #endif    /* VJCOMPRESS */
  133.         ifp->rxproc = newproc( ifn = if_name( ifp, " rx" ),
  134.             256,asy_rx,xdev,NULL,NULL,0);
  135.         free(ifn);
  136.     } else
  137. #endif
  138. #ifdef    AX25
  139.     if(stricmp(argv[3],"AX25") == 0) {
  140.         /* Set up a SLIP link to use AX.25 */
  141.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  142.             sp = &Slip[xdev];
  143.             if(sp->iface == NULLIF)
  144.                 break;
  145.         }
  146.         if(xdev >= SLIP_MAX) {
  147.             tprintf("Too many slip devices\n");
  148.             return -1;
  149.         }
  150.         setencap(ifp,"AX25");
  151.         ifp->ioctl = kiss_ioctl;
  152.         ifp->raw = kiss_raw;
  153.         ifp->show = slip_status;
  154.  
  155.         if(ifp->hwaddr == NULLCHAR)
  156.             ifp->hwaddr = mallocw(AXALEN);
  157.         memcpy(ifp->hwaddr,Mycall,AXALEN);
  158.         ifp->xdev = xdev;
  159.  
  160.         sp->iface = ifp;
  161.         sp->send = asy_send;
  162.         sp->get = get_asy;
  163.         sp->type = CL_KISS;
  164.         trigchar = FR_END;
  165.         ifp->rxproc = newproc( ifn = if_name( ifp, " rx" ),
  166.             256,asy_rx,xdev,NULL,NULL,0);
  167.         free(ifn);
  168.     } else
  169. #endif
  170. #ifdef    NRS
  171.     if(stricmp(argv[3],"NRS") == 0) {
  172.         /* Set up a net/rom serial iface */
  173.         for(xdev = 0;xdev < SLIP_MAX;xdev++){
  174.             np = &Nrs[xdev];
  175.             if(np->iface == NULLIF)
  176.                 break;
  177.         }
  178.         if(xdev >= SLIP_MAX) {
  179.             tprintf("Too many nrs devices\n");
  180.             return -1;
  181.         }
  182.         /* no call supplied? */
  183.         setencap(ifp,"AX25");
  184.         ifp->ioctl = asy_ioctl;
  185.         ifp->raw = nrs_raw;
  186.  
  187.         ifp->hwaddr = mallocw(AXALEN);
  188.         memcpy(ifp->hwaddr,Mycall,AXALEN);
  189.         ifp->xdev = xdev;
  190.         np->iface = ifp;
  191.         np->send = asy_send;
  192.         np->get = get_asy;
  193.         trigchar = ETX;
  194.         ifp->rxproc = newproc( ifn = if_name( ifp, " nrs" ),
  195.             256,nrs_recv,xdev,NULL,NULL,0);
  196.         free(ifn);
  197.     } else
  198. #endif
  199. #ifdef    PPP
  200.     if(stricmp(argv[3],"PPP") == 0) {
  201.         /* Setup for Point-to-Point Protocol */
  202.         trigchar = HDLC_FLAG;
  203.         monitor = TRUE;
  204.         setencap(ifp,"PPP");
  205.         ifp->ioctl = asy_ioctl;
  206.         ifp->flags = FALSE;
  207.  
  208.         /* Initialize parameters for various PPP phases/protocols */
  209.         if (ppp_init(ifp) != 0) {
  210.             tprintf("Cannot allocate PPP control block\n");
  211.             free(ifp->name);
  212.             free((char *)ifp);
  213.             return -1;
  214.         }
  215.     } else
  216. #endif
  217.     {
  218.         tprintf("Mode %s unknown for interface %s\n",
  219.             argv[3],argv[4]);
  220.         free(ifp->name);
  221.         free(ifp);
  222.         return -1;
  223.     }
  224.  
  225.     /* Link in the interface */
  226.     ifp->next = Ifaces;
  227.     Ifaces = ifp;
  228.  
  229.     /* Check user specified flags. - no Atari flags currently defined */
  230.  
  231.     asyp->user_flags = 0;
  232.  
  233. if (argc > 8) {
  234. #ifndef ATARI
  235.         if (strchr (argv[8], 'f') != 0) {
  236.             asyp->user_flags |= FORCE_16550;
  237.         }
  238.  
  239.         if (strchr (argv[8], 'n') != 0) {
  240.             asyp->user_flags |= NO_FLOW_CONTROL;
  241.         }
  242. #endif        
  243.     }
  244.  
  245.     asy_init(dev,ifp,argv[1],argv[2],(int16)atol(argv[5]),
  246.         trigchar,monitor,(int16)atol(argv[7]));
  247.     return 0;
  248. }
  249.  
  250.  
  251. static int
  252. asy_detach(ifp)
  253. struct iface *ifp;
  254. {
  255.     asy_stop(ifp);
  256.  
  257. #ifdef    SLIP
  258.     if(stricmp(ifp->iftype->name,"SLIP") == 0) {
  259.         Slip[ifp->xdev].iface = NULLIF;
  260. #ifdef VJCOMPRESS
  261.         slhc_free( Slip[ifp->xdev].slcomp );
  262.         Slip[ifp->xdev].slcomp = NULL;
  263. #endif    /* VJCOMPRESS */
  264.     } else
  265. #endif
  266. #ifdef    AX25
  267.     if(stricmp(ifp->iftype->name,"AX25") == 0
  268.      && Slip[ifp->xdev].iface == ifp ) {
  269.         Slip[ifp->xdev].iface = NULLIF;
  270.     } else
  271. #endif
  272. #ifdef    NRS
  273.     if(stricmp(ifp->iftype->name,"AX25") == 0
  274.      && Nrs[ifp->xdev].iface == ifp ) {
  275.         Nrs[ifp->xdev].iface = NULLIF;
  276.     } else
  277. #endif
  278. #ifdef    PPP
  279.     if(stricmp(ifp->iftype->name,"PPP") == 0) {
  280.         ppp_free(ifp);
  281.     } else
  282. #endif
  283.     {
  284.         tprintf("invalid type %s for interface %s\n",
  285.             ifp->iftype->name, ifp->name);
  286.         free(ifp->name);
  287.         free(ifp);
  288.         return -1;
  289.     }
  290.     return 0;
  291. }
  292.  
  293.  
  294.